﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.Entity;
using System.Data;

#region using for special implements
using Com.ProjectA.DAO;
using Com.ProjectA.BusinessLogic;
using Com.ProjectA.FAMvc.Areas.admin.Models;
using Com.ProjectA.FAMvc.MvcHtmlHelper;
using Com.ProjectA.Utility;
#endregion using for special implements


namespace Com.ProjectA.FAMvc.Areas.admin.Controllers
{
    public class SearchPersonController : Controller
    {
        //
        // GET: /admin/SearchPerson/
        //PersonDataContext pd = new PersonDataContext();

        public ActionResult Index()
        {
            //List<PersonModel> lsPerson = new List<PersonModel>();
            //lsPerson.Add(new PersonModel() { person_code="01",first_name="Nguyen",middle_name="aaa",birthday="25/01/2011" });
            return View("SearchResult");
        }

        public ActionResult SearchResult()
        {
        
            return View();
        }
               
        /*Tìm kiếm kết quả */
        [HttpGet]
        public ActionResult SearchResult(DAOPerson ps)
        {
            DAOPerson daoPerson = null;         
            BLPersonManager perMgnBl = null;
            string strMsgNotify = null;
            try
            {
                // Generate person code correlative to  sibling mode or descendent mode
                daoPerson = new DAOPerson() { person_code = ps.person_code,first_name=ps.first_name,middle_name=ps.middle_name,last_name=ps.last_name,birthday=ps.birthday,death_day=ps.death_day};
                perMgnBl = new BLPersonManager(Constants.STR_CONN_NAME);
                List<DAOPerson> lstPeople = new List<DAOPerson>();
                if (daoPerson.person_code == null)
                {
                    daoPerson.person_code = "";
                }
                if (daoPerson.first_name == null)
                {
                    daoPerson.first_name = "";
                }
                if (daoPerson.middle_name == null)
                {
                    daoPerson.middle_name = "";
                }
                if (daoPerson.last_name == null)
                {
                    daoPerson.last_name = "";
                }
                if (daoPerson.birthday == null)
                {
                    daoPerson.birthday = "";
                }
                if (daoPerson.death_day == null)
                {
                    daoPerson.death_day = "";
                }
                //strMsgNotify = perMgnBl.SearchPerson(daoPerson.person_code,daoPerson.first_name,daoPerson.middle_name,daoPerson.last_name,daoPerson.birthday,daoPerson.death_day, out lstPeople);
                return View("SearchResult", lstPeople);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
          
        }
    
    }
}
